﻿using System.Data;

namespace DataObject
{
    internal class StoredProcedures
    {
        private MainDB _db;

        public StoredProcedures(MainDB db)
        {
            _db = db;
        }

        public MainDB Database
        {
            get { return _db; }
        }

        protected DataSet CreateDataSet(IDbCommand command)
        {
            return _db.CreateDataSet(command);
        }

        protected DataTable CreateDataTable(IDbCommand command)
        {
            return _db.CreateDataTable(command);
        }

        #region News
        internal DataTable News_GetHighlightHomepage(int top, int status, int type, bool isHomePage)
        {
            var cmd = _db.CreateCommand("afe_News_GetHighlightHomepage", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            _db.AddParameter(cmd, "IsHomePage", DbType.Boolean, isHomePage);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable News_GetHighlightList(int top, int status, int type, bool isList)
        {
            var cmd = _db.CreateCommand("afe_News_GetHighlightList", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            _db.AddParameter(cmd, "IsList", DbType.Boolean, isList);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable News_GetListPaging(int status, int type, int pageIndex, int pageSize, string exceptionId)
        {
            var cmd = _db.CreateCommand("afe_News_GetListPaging", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            _db.AddParameter(cmd, "ExceptionId", DbType.String, exceptionId);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable News_Count(int status, int type, string exceptionId)
        {
            var cmd = _db.CreateCommand("afe_News_Count", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            _db.AddParameter(cmd, "ExceptionId", DbType.String, exceptionId);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable News_GetOtherNews(int status, int type, int pageIndex, int pageSize, string exceptionId)
        {
            var cmd = _db.CreateCommand("afe_News_GetOtherNews", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            _db.AddParameter(cmd, "ExceptionId", DbType.String, exceptionId);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable News_GetDetails(long id, int status, int type)
        {
            var cmd = _db.CreateCommand("afe_News_GetDetails", true);
            _db.AddParameter(cmd, "News_ID", DbType.Int64, id);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Type", DbType.Int32, type);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region QA
        internal DataTable QA_GetQAHomepage(int top, bool isActive, bool isFeature)
        {
            var cmd = _db.CreateCommand("afe_QA_GetQAHomepage", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "IsActive", DbType.Boolean, isActive);
            _db.AddParameter(cmd, "IsFeature", DbType.Boolean, isFeature);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable QA_GetListPaging(bool isActive, bool isFeature, int pageIndex, int pageSize)
        {
            var cmd = _db.CreateCommand("afe_QA_GetListPaging", true);
            _db.AddParameter(cmd, "IsActive", DbType.Boolean, isActive);
            _db.AddParameter(cmd, "IsFeature", DbType.Boolean, isFeature);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable QA_Count(bool isActive, bool isFeature)
        {
            var cmd = _db.CreateCommand("afe_QA_Count", true);
            _db.AddParameter(cmd, "IsActive", DbType.Boolean, isActive);
            _db.AddParameter(cmd, "IsFeature", DbType.Boolean, isFeature);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region City
        internal DataTable City_GetAll()
        {
            var cmd = _db.CreateCommand("afe_City_GetAll", true);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region Members
        internal DataTable Member_HighlightHomePage(int top, int status, int round)
        {
            var cmd = _db.CreateCommand("afe_Member_HighlightHomePage", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);            
        }

        internal DataTable Member_HighlightHomePage_Random(int top, int status, int round)
        {
            var cmd = _db.CreateCommand("afe_Member_HighlightHomePage_Random", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetList_Prev2(int status, int round, string keyword, int pageIndex, int pageSize)
        {
            var cmd = _db.CreateCommand("afe_Members_GetList_Prev2", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "Keyword", DbType.String, keyword);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetList(int status, int round, string orderstring, string keyword, int pageIndex, int pageSize)
        {
            var cmd = _db.CreateCommand("afe_Members_GetList", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "OrderString", DbType.String, orderstring);
            _db.AddParameter(cmd, "Keyword", DbType.String, keyword);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetList_Count_Prev2(int status, int round, string keyword)
        {
            var cmd = _db.CreateCommand("afe_Members_GetList_Count_Prev2", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "Keyword", DbType.String, keyword);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetList_Count(int status, int round, int ordertype, string keyword)
        {
            var cmd = _db.CreateCommand("afe_Members_GetList_Count", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "OrderType", DbType.Int32, ordertype);
            _db.AddParameter(cmd, "Keyword", DbType.String, keyword);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetByEmailFrontEnd(int status, int round, string email)
        {
            var cmd = _db.CreateCommand("afe_Members_GetByEmailFrontEnd", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "Email", DbType.String, email);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_GetByIdFrontEnd(int status, int round, int id)
        {
            var cmd = _db.CreateCommand("afe_Members_GetByIdFrontEnd", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "Member_ID", DbType.String, id);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Members_InSlide(int top, int status, int round)
        {
            var cmd = _db.CreateCommand("afe_Members_InSlide", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region photos
        internal DataTable Photos_GetByMemberID(int id, int round)
        {
            var cmd = _db.CreateCommand("afe_Photos_GetByMemberID", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, id);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Photos_CountByMemberID(int id, int round)
        {
            var cmd = _db.CreateCommand("afe_Photos_CountByMemberID", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, id);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Photos_DeleteById(int id)
        {
            var cmd = _db.CreateCommand("afe_Photos_DeleteById", true);
            _db.AddParameter(cmd, "Photo_ID", DbType.Int32, id);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Photos_DeleteByMemberId(int id, int round)
        {
            var cmd = _db.CreateCommand("afe_Photos_DeleteByMemberId", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, id);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable InsertPhotoRound(int Member_ID, string Photo_Title, string Photo_Description,string size, string Photo_Url, int Photo_Round)
        {
            var cmd = _db.CreateCommand("afe_Insert_Photos_ByMemberID", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, Member_ID);
            _db.AddParameter(cmd, "Photo_Title", DbType.String, Photo_Title);
            _db.AddParameter(cmd, "Photo_Description", DbType.String, Photo_Description);
            _db.AddParameter(cmd, "Photo_Size", DbType.String, size);
            _db.AddParameter(cmd, "Photo_Url", DbType.String, Photo_Url);
            _db.AddParameter(cmd, "Photo_Round", DbType.Int32, Photo_Round);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable UpdatePhotoRound(int Member_ID, int Photo_ID, string Photo_Description)
        {
            var cmd = _db.CreateCommand("afe_Members_UpdateFrontEnd", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, Member_ID);
            _db.AddParameter(cmd, "Photo_ID", DbType.Int32, Photo_ID);
            _db.AddParameter(cmd, "Photo_Description", DbType.String, Photo_Description);
            return _db.CreateDataTable(cmd);
        }

        internal DataTable Photos_ListAllPhotoPaging(int status, int round, int pageIndex, int pageSize)
        {
            var cmd = _db.CreateCommand("afe_Photos_GetByRoundPaging", true);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region ref
        internal DataTable Ref_GetRefByKey(int top, string key)
        {
            var cmd = _db.CreateCommand("afe_Ref_GetTop1RefByKey", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "Key", DbType.String, key);
            return _db.CreateDataTable(cmd);
        }
        #endregion

        #region vote
        internal DataTable Vote_GetVoteLogByFromID(int id)
        {
            var cmd = _db.CreateCommand("afe_VoteLog_GetVoteLogByFromID", true);
            _db.AddParameter(cmd, "VoteLog_FromID", DbType.Int32, id);
            return _db.CreateDataTable(cmd);
        }


        internal DataTable Members_GetVoteByRound(int id, int status, int round)
        {
            var cmd = _db.CreateCommand("afe_Members_GetVoteByRound", true);
            _db.AddParameter(cmd, "Member_ID", DbType.Int32, id);
            _db.AddParameter(cmd, "Status", DbType.Int32, status);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            return _db.CreateDataTable(cmd);
        }
        #endregion
    }
}
